<template>
    <header>
        <div class="l-content">
            <el-button @click="handleMenu" plain icon="el-icon-menu" size="mini"></el-button>
            <!--      <h3 style="color: #ffffff">首页</h3>-->
            <!--      <el-breadcrumb separator="/">
        <el-breadcrumb-item v-for="item in tags" :key="item.path" :to="{ path: item.path }">{{item.label}}</el-breadcrumb-item>
      </el-breadcrumb>-->
        </div>
        <div class="r-content">
            <el-button @click="test">测试</el-button>
            <el-dropdown trigger="click" size="mini">
                <span>
                    <img class="user" :src="userImg" />
                </span>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item @click.native="getInfo">个人信息</el-dropdown-item>
                    <el-dropdown-item @click.native="loginOut">退出</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </div>
    </header>
</template>
<script>
import { mapGetters, mapState } from 'vuex'
import { loginOut, test } from '@/api/login'
import store from '@/store'
import cache from '@/plugins/cache'
export default {
    data() {
        return {
            userImg: store.getters.avatar
        }
    },
    methods: {
        handleMenu() {
            this.$store.commit('collapseMenu')
        },
        loginOut() {
            loginOut().then((res) => {
                // this.$cookie.set('token', undefined)
                cache.session.setJSON('token', undefined)
                this.$message(res.data.msg)
                this.$router.push({ path: '/' })
            })
        },
        getInfo() {
            this.$router.push({ path: '/personInfo' })
        },
        test() {
            test({ password: 4444, userName: '4444aaa4' }).then((res) => {
                this.$message(res.data.msg)
            })
            // this.download("user/test2", {}, `user_${new Date().getTime()}.xlsx`);
        }
    },
    computed: {
        ...mapState({
            tags: (state) => state.tab.tabsList
        }),
        // ...mapGetters(['avatar']),
        avatar() {
            return store.getters.avatar
        }
    },
    watch: {
        avatar(n, o) {
            this.userImg = n
        }
    }
}
</script>
<style lang="less" scoped>
header {
    display: flex;
    height: 100%;
    justify-content: space-between;
    align-items: center;
}

.l-content {
    display: flex;
    align-items: center;

    .el-button {
        margin-right: 20px;
    }
}
.r-content {
    .user {
        width: 40px;
        height: 40px;
        border-radius: 50%;
    }
}
</style>
